import com.google.gmeetings.User
import com.google.gmeetings.auth.SecRole
import com.google.gmeetings.auth.SecUserSecRole

class BootStrap {

    def init = { servletContext ->
        def adminRole = SecRole.findByAuthority('ROLE_ADMIN') ?: new SecRole(authority: 'ROLE_ADMIN').save(failOnError: true)
        def userRole = SecRole.findByAuthority('ROLE_USER') ?: new SecRole(authority: 'ROLE_USER').save(failOnError: true)

        def adminUser = User.findByUsername('admin') ?: new User(
                username: 'admin',
                password: 'admin',
                email: 'admin@gmeetings.com',
                name: 'Administrator',
                street: 'Administrator Street',
                enabled: true).save(failOnError: true)

        if (!adminUser.authorities.contains(adminRole)) {
            SecUserSecRole.create(adminUser, adminRole)
        }

        def normalUser = User.findByUsername('user') ?: new User(
                username: 'user',
                password: 'user',
                email: 'user@gmeetings.com',
                name: 'User',
                street: 'User Street',
                enabled: true).save(failOnError: true)

        if (!normalUser.authorities.contains(userRole)) {
            SecUserSecRole.create(normalUser, userRole)
        }
    }
    def destroy = {
    }
}
